import java.util.Random;

import de.mlp_distributed.mlp.math.jblas.JDenseVector;
import de.mlp_distributed.mlp.math.mahout.DenseVector;
import de.mlp_distributed.mlp.math.mahout.Matrix;
import de.mlp_distributed.mlp.math.mahout.RandomUtils;

public class SpeedTestMahout {

	final static int columnSize = 10000;
	final static int rowSize = 50000;

	private static final Random gen = RandomUtils.getRandom();

	static double[] constructVectorArray(final int csize) {
		RandomUtils.useTestSeed();
		final double[] returnVal = new double[csize];
		for (int j = 0; j < csize; j++) {
			double w = 0;
			w = 1.73d / Math.sqrt(csize);
			w = ((2.0 * SpeedTestMahout.gen.nextDouble()) - 1.0) * w;
			returnVal[j] = w;
		}
		return returnVal;
	}

	static double[][] constructMatrixArray(final int csize, final int rsize) {
		RandomUtils.useTestSeed();
		final double[][] returnVal = new double[rsize][csize];
		final int fanIn = csize;
		final int fanOut = rsize;
		for (int i = 0; i < fanOut; i++) {
			for (int j = 0; j < fanIn; j++) {
				double w = 0;
				if (i != 0) {
					w = 1.73d / Math.sqrt(fanIn);
					w = ((2.0 * SpeedTestMahout.gen.nextDouble()) - 1.0) * w;
				}
				returnVal[i][j] = w;
			}
		}
		return returnVal;
	}

	public static void main(final String[] args) {
		SpeedTestMahout.testCross();
	}

	static void testCross() {
		final double[] vector = SpeedTestMahout.constructVectorArray(SpeedTestMahout.columnSize);

		final JDenseVector jdv = new JDenseVector(vector.clone());
		final DenseVector dv = new DenseVector(vector.clone());

		final JDenseVector jtarget = new JDenseVector(vector.clone());
		final DenseVector target = new DenseVector(vector.clone());
		long startTime = 0;
		for (int i = 0; i < 10; i++) {
			startTime = System.currentTimeMillis();
			final Matrix result = jdv.cross(jtarget);
			System.out.println("jblas cross " + ((System.currentTimeMillis() - startTime) / 1000.0) + " seconds");

			startTime = System.currentTimeMillis();
			final Matrix result2 = dv.cross(target);
			System.out.println("mahout cross " + ((System.currentTimeMillis() - startTime) / 1000.0) + " seconds");
		}

	}

}
